package com.shangcheng.server.controller;
import com.shangcheng.model.domain.SmsHomeBrand;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsHomeBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiqiang
 * @version 1.0
 * @date 2022/5/12 14:20
 */
@RestController
@RequestMapping("/home/brand")
public class SmsHomeBrandController {
    @Autowired
    private SmsHomeBrandService homeBrandService;

    /**
     * 分页查询推荐品牌列表
     * @param pageNum
     * @param pageSize
     * @param brandName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity brandList(@RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,String brandName,Integer recommendStatus){
        PageResult result= homeBrandService.brandList(pageNum,pageSize,brandName,recommendStatus);
        return ResponseEntity.ok(new Result(200,result,null));
    }

    /**
     * 修改推荐品牌排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity updateSort(@PathVariable("id") Integer id,@RequestParam Integer sort){
        homeBrandService.updateSort(id,sort);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity delete(Integer[] ids){
        homeBrandService.delete(ids);
        return ResponseEntity.ok(new Result(200,null,"删除成功"));
    }

    /**
     * 批量修改推荐品牌
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity updateRecommendStatus( Integer[] ids, Integer recommendStatus){
        homeBrandService.updateRecommendStatus(ids,recommendStatus);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }

    /**
     * 批量添加首页推荐品牌
     * @param homeBrandList 推荐品牌集合
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity create(@RequestBody List<SmsHomeBrand> homeBrandList){
        homeBrandService.create(homeBrandList);
        return ResponseEntity.ok(new Result(200,null,"添加成功"));
    }
}
